using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.Storage;
using System.ServiceModel;
using System.ServiceModel.Syndication;
using System.Xml;
using System.Configuration;


namespace RssReaderCrawler
{
    public class WorkerRole : RoleEntryPoint
    {
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.TraceInformation("RssReaderCrawler entry point called", "Information");

            while (true)
            {
                Thread.Sleep(10000);
                Trace.TraceInformation("Working", "Information");
                XmlReader xr = XmlReader.Create("http://www.newsmth.net/nForum/rss/topten");
                SyndicationFeed sf = SyndicationFeed.Load(xr);
                foreach (var item in sf.Items)
                {
                    Trace.TraceInformation(item.Id, "Information");
                    Trace.TraceInformation(item.Title.Text, "Information");
                    Trace.TraceInformation(item.Id, "Information");

                    Trace.TraceInformation(ConfigurationManager.ConnectionStrings["rssDB2"].ConnectionString, "Information");
                    
                }
                xr.Close();
            }
        }

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            return base.OnStart();
        }
    }
}
